package com.yanqu.road.server.cmd.activity.signindraw;

import com.yanqu.road.entity.activity.signindraw.SignInDrawConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SignInDrawProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.signindraw.SignInDrawModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.signindraw.SignInDrawActivityMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@CmdApi(reqMsg = SignInDrawProto.SignInDrawOnlineTodayReqMsg.class, respMsg = SignInDrawProto.SignInDrawOnlineTodayRespMsg.class)
@Cmd(code = Protocol.S_SIGN_IN_DRAW_SETTLE_ONLINE, desc = "在线时长")
public class SignInDrawOnlineTodayCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        // 没有活动
        SignInDrawConfig config = SignInDrawActivityMgr.getConfig();
        if (config == null || !ActivityMgr.activityInTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }

        ret = player.getModule(SignInDrawModule.class).onlineReward();

    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_SIGN_IN_DRAW_SETTLE_ONLINE, SignInDrawProto.SignInDrawOnlineTodayRespMsg.newBuilder().setRet(ret));
        }
    }
}
